package org.dromara.vmp.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.vmp.domain.bo.MonitorAreaBo;
import org.dromara.vmp.domain.vo.MonitorAreaVo;
import org.dromara.vmp.service.IMonitorAreaService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 监控区域
 *
 * @author LSL
 * @date 2024-05-21
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/wvp/monitorArea")
public class MonitorAreaController extends BaseController {

    private final IMonitorAreaService monitorAreaService;

    /**
     * 查询监控区域列表
     */
    @SaCheckPermission("wvp:monitorArea:list")
    @GetMapping("/list")
    public TableDataInfo<MonitorAreaVo> list(MonitorAreaBo bo, PageQuery pageQuery) {
        return monitorAreaService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出监控区域列表
     */
    @SaCheckPermission("wvp:monitorArea:export")
    @Log(title = "监控区域", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(MonitorAreaBo bo, HttpServletResponse response) {
        List<MonitorAreaVo> list = monitorAreaService.queryList(bo);
        ExcelUtil.exportExcel(list, "监控区域", MonitorAreaVo.class, response);
    }

    /**
     * 获取监控区域详细信息
     *
     * @param maId 主键
     */
    @SaCheckPermission("wvp:monitorArea:query")
    @GetMapping("/{maId}")
    public R<MonitorAreaVo> getInfo(@NotNull(message = "主键不能为空")
                                    @PathVariable Long maId) {
        return R.ok(monitorAreaService.queryById(maId));
    }

    /**
     * 新增监控区域
     */
    @SaCheckPermission("wvp:monitorArea:add")
    @Log(title = "监控区域", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody MonitorAreaBo bo) {
        return toAjax(monitorAreaService.insertByBo(bo));
    }

    /**
     * 修改监控区域
     */
    @SaCheckPermission("wvp:monitorArea:edit")
    @Log(title = "监控区域", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody MonitorAreaBo bo) {
        return toAjax(monitorAreaService.updateByBo(bo));
    }

    /**
     * 删除监控区域
     *
     * @param maIds 主键串
     */
    @SaCheckPermission("wvp:monitorArea:remove")
    @Log(title = "监控区域", businessType = BusinessType.DELETE)
    @DeleteMapping("/{maIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] maIds) {
        return toAjax(monitorAreaService.deleteWithValidByIds(List.of(maIds), true));
    }
}
